<template>
	<view class="ys">
		<view class="tar">
			<view :class="type == item.type?'item on':'item'" v-for="(item,index) in list" :key="index"
				@click="changeType(item)">
				<i class="iconfont" :class="item.icon"></i>
				<text>{{item.text}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				route: '',
				type: 'home'
			}
		},
		props: {
			list: {
				type: Array,
				default: () => {
					return [{
							icon: 'icon-shouye',
							url: '',
							text: '首页',
							type: 'home'
						},
						{
							icon: 'icon-wodedamaijihuo',
							url: '',
							text: '消息',
							type: 'msg'
						},
						{
							icon: 'icon-xiaoxi',
							url: '',
							text: '我的',
							type: 'mine'
						}
					]
				}
			}
		},
		created() {
			//获取当前路由
			let pages = getCurrentPages();
			let currentPage = pages[pages.length - 1];
			this.route = currentPage.route
		},
		methods: {
			changeType(item) {
				if (this.type === item.type) {
					return
				}
				this.type = item.type
				uni.$emit('changeType', this.type)
			}
		}
	}
</script>

<style lang="scss">
	.tar {
		display: flex;
		position: fixed;
		bottom: 0;
		height: 54px;
		align-items: center;
		width: 100%;
		border-top: 2px solid #00000008;
		background: #fff;

		.item {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			i {
				color: #E8E8E8;
				font-size: 22px;
				transition: .3s;
			}

			text {
				font-size: 14px;
				color: #C2C2C2;
				margin-top: 2px;
				transition: .3s;
			}

			&.on {

				i,
				text {
					color: #FC7941;
				}
			}
		}
	}
</style>